package br.estacio.contatos.client;

import br.estacio.contatos.client.i18n.ContatosConstants;
import br.estacio.contatos.client.service.ContatoRemoteService;
import br.estacio.contatos.client.service.ContatoRemoteServiceAsync;
import br.estacio.contatos.client.ui.ContatoView;
import br.estacio.contatos.client.ui.EditarContactViewImpl;
import br.estacio.contatos.client.ui.ListarContatoView;
import br.estacio.contatos.client.ui.ListarContatoViewImpl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.place.shared.PlaceController;

@SuppressWarnings("deprecation")
public class ClientFactoryImpl implements ClientFactory {
	
	private static final EventBus eventBus = new SimpleEventBus();
	private static final PlaceController placeController = new PlaceController(eventBus);
	private static ContatoView contatoView;
	private static ListarContatoView listarContatoView;
	private static final ContatoRemoteServiceAsync contatoRemoteServiceAsync = GWT.create(ContatoRemoteService.class);
	private static final ContatosConstants contatoConstants = GWT.create(ContatosConstants.class);

	@Override
	public EventBus getEventBus() {
		return eventBus;
	}

	@Override
	public PlaceController getPlaceController() {
		return placeController;
	}

	@Override
	public ContatoView getEditarContatoView() {
		if(contatoView == null) {
			contatoView = new EditarContactViewImpl(getEventBus(), getContatosConstants());
		}
		return contatoView;
	}

	@Override
	public ListarContatoView getListarContatoView() {
		if(listarContatoView == null) {
			listarContatoView = new ListarContatoViewImpl(getContatosConstants());
		}
		return listarContatoView;
	}

	@Override
	public ContatoRemoteServiceAsync getContatoRemoteServiceAsync() {
		return contatoRemoteServiceAsync;
	}

	@Override
	public ContatosConstants getContatosConstants() {
		return contatoConstants;
	}

}
